//
//  DSEMarketHandle.m
//  qqqqqq
//
//  Created by iOSer on 2017/3/17.
//  Copyright © 2017年 iOSer. All rights reserved.
//

#import "LEMarketHandle.h"
#import "LEProbabilityHandle.h"
#import "LECommodity.h"
@interface LEMarketHandle()
@property(nonatomic,copy) NSArray *baseArray;
@end
@implementation LEMarketHandle

//计算商品事件触发概率
-(NSString *)calculateTriggerProbability:(NSMutableArray *)arrM{
    
        NSString *isTrigger = [LEProbabilityHandle computeProbability:@[
                                                                         
                                                                         @{@"id":@"YES",@"Probability":[NSNumber numberWithDouble:0.4]},
                                                                         @{@"id":@"NO",@"Probability":[NSNumber numberWithDouble:0.6]}
                                                                         ]];
    if ([isTrigger isEqualToString:@"YES"]) {
        NSMutableArray *showArray = [[NSMutableArray alloc] initWithCapacity:21];
        for (LECommodity *com in arrM) {
            for (NSDictionary *dic in self.baseArray) {
                if ([dic[@"id"] isEqualToString:com.name]) {
                    [showArray addObject:dic];
                }
            }
        }
        return [LEProbabilityHandle computeProbability:showArray];
    }else{
        return @"";
    }
}
//计算涨价降价概率
-(NSString *)calculateLowORHighlightProbability{
    NSString *isTrigger = [LEProbabilityHandle computeProbability:@[
                                                                    @{@"id":@"Low",@"Probability":[NSNumber numberWithDouble:0.5]},
                                                                    @{@"id":@"Hi",@"Probability":[NSNumber numberWithDouble:0.5]}
                                                                    ]];
    
    
    return isTrigger;
}

//计算商品显示概率 判断从数据源中删除哪个商品
-(NSString *)calculateCommodityShowProbability{
    
    NSMutableArray *array =[[NSMutableArray alloc] initWithArray:@[
                                                                   @{@"id":@"Q20汽车",@"Probability":[NSNumber numberWithDouble:0.3]},
                                                                   @{@"id":@"橘子电脑",@"Probability":[NSNumber numberWithDouble:0.3]},
                                                                   @{@"id":@"爱疯7P",@"Probability":[NSNumber numberWithDouble:0.2]},
                                                                   @{@"id":@"24K氪金",@"Probability":[NSNumber numberWithDouble:0.2]},
                                                                   @{@"id":@"扩容U盘",@"Probability":[NSNumber numberWithDouble:0.2]},
                                                                   @{@"id":@"大米手环",@"Probability":[NSNumber numberWithDouble:0.2]},
                                                                   @{@"id":@"浓香地沟油",@"Probability":[NSNumber numberWithDouble:0.2]},
                                                                   @{@"id":@"前男友面膜",@"Probability":[NSNumber numberWithDouble:0.1]},
                                                                   @{@"id":@"爽歪歪口罩",@"Probability":[NSNumber numberWithDouble:0.1]},
                                                                   @{@"id":@"AV光盘",@"Probability":[NSNumber numberWithDouble:0.1]},
                                                                   ]];
    NSString *key = [LEProbabilityHandle computeProbability:array];
    
    
    
    return key;
}
//计算行为概率
-(NSString *)calculateBehaviorProbability{
    NSString *isTrigger = [LEProbabilityHandle computeProbability:@[
                                                                    
                                                                    @{@"id":@"YES",@"Probability":[NSNumber numberWithDouble:0.1]},
                                                                    @{@"id":@"NO",@"Probability":[NSNumber numberWithDouble:0.9]}
                                                                    ]];
    if ([isTrigger isEqualToString:@"YES"]) {
        NSMutableArray *array =[[NSMutableArray alloc] initWithArray:@[
                                                                       @{@"id":@"小偷",@"Probability":[NSNumber numberWithDouble:0.5]},
                                                                       @{@"id":@"挨打",@"Probability":[NSNumber numberWithDouble:0.5]},
                                                                       ]];
        
        NSString *key = [LEProbabilityHandle computeProbability:array];
        return key;
    }else{
        return @"";
    }

 
}


-(NSArray *)baseArray{
    if (!_baseArray) {
        _baseArray = @[
                       @{@"id":@"Q20汽车",@"Probability":[NSNumber numberWithDouble:0.3]},
                       @{@"id":@"橘子电脑",@"Probability":[NSNumber numberWithDouble:0.3]},
                       @{@"id":@"爱疯7P",@"Probability":[NSNumber numberWithDouble:0.2]},
                       @{@"id":@"24K氪金",@"Probability":[NSNumber numberWithDouble:0.2]},
                       @{@"id":@"扩容U盘",@"Probability":[NSNumber numberWithDouble:0.2]},
                       @{@"id":@"大米手环",@"Probability":[NSNumber numberWithDouble:0.2]},
                       @{@"id":@"浓香地沟油",@"Probability":[NSNumber numberWithDouble:0.2]},
                       @{@"id":@"前男友面膜",@"Probability":[NSNumber numberWithDouble:0.1]},
                       @{@"id":@"爽歪歪口罩",@"Probability":[NSNumber numberWithDouble:0.1]},
                       @{@"id":@"AV光盘",@"Probability":[NSNumber numberWithDouble:0.1]},
                       ];
    }
    return _baseArray;
}
@end
